<script>
	import {
		mapMutations
	} from 'vuex'
	export default {
		onLaunch: function() {
			console.warn('当前组件仅支持 uni_modules 目录结构 ，请升级 HBuilderX 到 3.1.0 版本以上！')
			console.log('App Launch')
			uni.getStorage({
				key: 'userInfo',
				success: (res) => {
					console.log(res)
					//将用户信息保存到vuex
					this.storeLogin(JSON.parse(res.data))
				}
			})
		},
		onShow: function() {
			console.log('App Show')
			//广告显示的时间 
			let adShowTime = 10 * 60 * 1000
			//当前时间
			let nowTime = (new Date()).getTime()
			//开始隐藏的时间
			let leaveTime = this.$store.state.leaveTime
			// console.log("onshow:", nowTime, leaveTime);
			//开始比较
			if ((nowTime - leaveTime) >= adShowTime) {
				// console.log(' show ad');
				uni.navigateTo({
					url: '/pages/ad/ad'
				})
			}
		},
		onHide: function() {
			console.log('App Hide')
			//记录app隐藏的开始时 间
			this.$store.commit('storeLeaveTime')
		},
		methods: {
			...mapMutations(['storeLogin', 'storeLeaveTime'])
		}
	}
</script>

<style lang="scss">

	@import url('./common/css/common.scss');
	@import url("./common/css/iconfont.css")
</style>